package at.ac.tuwien.prog.command;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import at.ac.tuwien.prog.entity.Register;
import at.ac.tuwien.prog.system.ISystem;

/**
 *
 * Schreibe B (als Konstante) in Register A (bzw. springe zur Adresse B fuer A = -8192).
 * 
 * @author christoph.pickl@student.tuwien.ac.at
 */
public class SetConstantCommand extends AbstractCommand {
	
	private static final Log LOG = LogFactory.getLog(SetConstantCommand.class);

	public static final String NAME = "setc";

	/**
	 * @param registerAddress target address
	 * @param constantValue value to store in register
	 */
	public SetConstantCommand(int registerAddress, int constantValue) {
		super(registerAddress, constantValue);
	}

	public void execute(final ISystem system) {
		final int registerAddress = this.getOperand1();
		final Register constantValue = Register.newByInt(this.getOperand2());
		LOG.info("execute(registerAddress="+registerAddress+"; constantValue="+constantValue+")");
		
		system.getMemoryManager().setRegisterValue(registerAddress, constantValue);
		
	}

}
